/**
 * @Title: ResultCode.java
 * @Package com.charging.modelVo.result
 * @Description: TODO(用一句话描述该文件做什么)
 * @author ZKzha
 * @date 2019年8月14日 下午5:15:55
 * @version V1.0
 */
package com.bogo.dbtable.tool.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZKzha
 * @date 2019-08-14 17:15
 */
public enum ResultCode {

    /**
     * 成功状态码
     */
    SUCCESS(1, "成功"),

    /* 参数错误：10001-19999 */
    PARAM_IS_INVALID(10001, "参数无效"),
    PARAM_IS_BLANK(10002, "参数为空"),
    PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
    PARAM_NOT_COMPLETE(10004, "参数缺失"),
    PARAM_TIME_ERROR(10005, "时间格式错误"),
    PASS_ERROR(10006, "密码错误"),
    PASS_OUTTIME(10007, "密码过期"),
    NAME_IS_EXSIT(10008, "该名已存在"),
    REASON_IS_NONE(10009, "审核原因不能为空"),
    VCODE_IS_OUT(10010, "验证码已经过期了"),
    PASS_IS_ERROR(10011,"请输入至少八位的密码，包含数字、大写字母、小写字母和特殊字符"),
    IDCARD_IS_ERROR(10012,"身份证号码错误"),
    PARAM_PHONE_ERROR(10013,"手机号错误"),
    FILE_NAME_IS_NONE(10014,"文件名为空"),

    /* 用户错误：20001-29999*/
    USER_NOT_LOGGED_IN(20001, "用户未登录"),
    USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
    USER_NOT_FOUND(20004, "账户未找到或密码错误"),
    ROLE_NOT_FOUND(20005, "角色未找到"),
    USER_IS_OUTTIME(20006, "账户已过期"),
    USER_IS_AUDIT(20007, "账户已审核通过"),
    USER_ACCOUNT_LOCKED(20008,"账户被锁定"),
    USER_NOT_REGISTER(20009, "请先联系管理员添加账户"),
    IDCARD_IS_EXIT(20010,"该身份证号已存在"),
    USER_IS_EXIT(20011,"该用户已注册"),

    /* 业务错误：30001-39999 */
    SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "业务错误"),
    SPECIFIED_QUESTIONED_UPLOAD_ERROR(30002, "文件上传失败"),
    SPECIFIED_QUESTIONED_UPLOAD_FILE_EMPTY(30003, "文件上传内容为空"),
    SAME_PHONE_OVER(30004, "超过每日发送上限"),
    VCODE_TIME_LIMIT(30005, "验证码发送需要间隔120秒"),
    USER_REGISTER_ERROR(30006,"绑定失败，请稍后再试"),
    VISITER_REGISTER_ERROR(30007,"注册失败，请稍后再试"),
    FILE_UP_ERROR(30008,"文件上传错误"),
    HOURS_IS_NONE(30009,"产权信息不存在"),
    HOURS_PERMISSION_WRONG(30010,"您不是该产权的负责人，不能修改该产权进度"),
    PLAN_STATE_ERROR(30011,"计划状态已修改"),

    /* 系统错误：40001-49999 */
    SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),
    SYSTEM_UPDATE_ERROR(40002, "系统繁忙，更新失败"),
    SYSTEM_INSERT_ERROR(40003, "系统繁忙，插入失败"),
    SYSTEM_DELETE_ERROR(40004, "系统繁忙，删除失败"),

    /* 数据错误：50001-599999 */
    RESULE_DATA_NONE(50001, "数据未找到"),
    DATA_IS_WRONG(50002, "数据有误"),
    DATA_ALREADY_EXISTED(50003, "数据已存在"),

    /* 接口错误：60001-69999 */
    INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
    INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
    INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
    INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
    INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
    INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),
    INTERFACE_REQUEST_ERROR(60007, "接口请求方式错误"),
    INTERFACE_MEDIA_ERROR(60008, "content-type方式错误"),
    INTERFACE_JSON_ERROR(60009,"json解析异常"),
    SERVICE_NOT_FOUND(60010,"服务未启动，请稍后再试"),

    /* 权限错误：70001-79999 */
    PERMISSION_NO_ACCESS(70001, "无访问权限"),
    RESOURCE_EXISTED(70002, "资源已存在"),
    RESOURCE_NOT_EXISTED(70003, "资源不存在"),
    PERMISSION_DENIED(70004, "权限不足，操作被拒绝"),
    TOKEN_IS_NONE(70005, "访问令牌错误"),
    TOKEN_IS_WARN(70006, "密钥不正确"),
    TOKEN_IS_ERROR(70007, "非法请求"),
    TOKEN_OR_LOGIN_NONE(70008,"未登录或访问令牌过期");


    private Integer code;

    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

    /***
     * 校验重复的code值
     */
    static void main(String[] args) {
        ResultCode[] apiResultCodes = ResultCode.values();
        List<Integer> codeList = new ArrayList<Integer>();
        for (ResultCode apiResultCode : apiResultCodes) {
            if (codeList.contains(apiResultCode.code)) {
                System.out.println(apiResultCode.code);
            } else {
                codeList.add(apiResultCode.code());
            }

            System.out.println(apiResultCode.code() + " " + apiResultCode.message());
        }
    }
}
